$input a_position, a_normal, a_texcoord0, a_color0, i_data0, i_data1, i_data2, i_data3
$output v_texcoord0, v_color0, v_wnormal, v_wpos, v_view

#include <bgfx_shader.sh>
#include <rider_lib.sh>

uniform vec3 u_cameraPos;

void main()
{
    mat4 model = mtxFromCols(i_data0, i_data1, i_data2, i_data3);
    vec4 worldPos = mul(model, vec4(a_position, 1.0));
    gl_Position = mul(u_viewProj, worldPos);
	v_texcoord0 = a_texcoord0;
    v_color0 = a_color0;

    mat3 normalMat = transpose(inverseMat3(mat3(model)));
    v_wnormal = normalize(mul(normalMat, a_normal));

    v_wpos = worldPos.xyz;

    v_view = normalize(u_cameraPos - v_wpos);
}
